<?php 
// TODO закешировать по SQL-запросу
$cities = City::model()->findAll('', array('order'=>'caption'));
// подготовка данных
$arrCity = array();
foreach ($cities as $i => $city) {
	$firstLetter = mb_substr($city->caption, 0, 2);
	$arrCity[$firstLetter][] = array('url' => '/catalog/'.$city->url_code.'/', 'caption' => $city->caption);
}
?>
<div class="title">Выбрать город</div>
<?php //<input type="text" placeholder="Быстрый поиск"/>?>
<div class="list-citys">
<?php $count = count($arrCity);
$i = 0; $col = 1;
if ($count > 1)
	$numbInCol = $count%3 == 0 ? $count/3 : ($count - $count%3) / 2;
else 
	$numbInCol = $count;
foreach ($arrCity as $cityLetter => $cities) {
	if ($i % $numbInCol == 0) {
		echo '<div class="column cl'.$col.'">';
		$col++;
	}
	echo '<div class="letter"><span class="zg">'.$cityLetter.'</span>';
	foreach ($cities as $city) {
		//echo '<input type="radio" name="cc"  id="cc'.$i.'"/>';
		//echo '<label for="cc'.$i.'"><span>'.$city['caption'].'</span></label><br/>';
		echo '<label for="cc'.$i.'"><a href="'.$city['url'].'"><span>'.$city['caption'].'</span></a></label><br/>';
		$i++;
	}
	echo '</div>';
	if (($i+1)%$numbInCol == 0 || $i+1 == $count) {
		echo '</div>';
	}
}
?>
<div class="clr"></div>
</div>
<a class="close-reveal-modal">Close</a>